/**
* GTweenFilter by Grant Skinner. Dec 15, 2008
* Visit www.gskinner.com/blog for documentation, updates and more free code.
*
*
* Copyright (c) 2008 Grant Skinner
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
**/

package com.gskinner.motion {
	
	import com.gskinner.motion.GTween;
	
	/**
	* <b>GTweenFilter ©2008 Grant Skinner, gskinner.com. Visit www.gskinner.com/blog for documentation, updates and more free code. Licensed under the MIT license. See the source file header for more information.</b>
	* <hr>
	* GTweenFilter is an extension to GTween, a light-weight instance oriented tween engine. It allows you to tween the properties of filters on display objects.
	* Using GTweenFilter is almost identical to using GTween. The only major difference is that you can specify a filterIndex (which defaults to 0) to indicate which filter in the target objects
	* .filters array will be affected by the Tween. You can use multiple instances of GTweenFilter with different filterIndexes to tween multiple filters on a single target.
	* GTweenFilter adds ~0.3kb above GTween.
	**/
	
	public class GTweenFilter extends GTween {
		
	// Constants:
	// Public Properties:
		/** Indicates the index of the filter in the target's .filters array to apply the tween to. Defaults to 0, which will tween the first filter in the target's filters array. **/
		public var filterIndex:uint=0;
		
	// Private Properties:
	
	// Initialization:
		/**
		* Constructs a new GTweenFilter instance. See the GTween documentation for a description of the parameters.
		**/
		public function GTweenFilter(target:Object=null, duration:Number=10, properties:Object=null, tweenProperties:Object=null) {
			super(target,duration,properties,tweenProperties);
		}
	
	// Public getter / setters:
		override public function get propertyTarget():Object {
			updatePropertyTarget();
			return _propertyTarget;
		}
	
	// Public Methods:
		
	// Protected Methods:
		/** @private **/
		protected function updatePropertyTarget():void {
			_propertyTarget = _target.filters[filterIndex];
			if (_propertyTarget == null) {
				throw(new Error("GTweenFilter: no filter at index '"+filterIndex+"'."));
			}
		}
		
		/** @private **/
		override protected function updateProperties():void {
			updatePropertyTarget()
			super.updateProperties();
			var filters:Array = _target.filters;
			filters[filterIndex] = _propertyTarget;
			_target.filters = filters;
		}
		
		/** @private **/
		override protected function init():void {
			updatePropertyTarget()
			super.init();
		}
	}
	
}